const sequelize = require("../sequelize_ins");
const { DataTypes } = require("sequelize");

const core = sequelize.define("pb_time", {
  d_id: { type: DataTypes.INTEGER, unique: "unique_key" },
  time_type: { type: DataTypes.INTEGER, unique: "unique_key" },
  from: DataTypes.STRING,
  to: DataTypes.STRING,
  op_type: DataTypes.INTEGER,
  nums: DataTypes.INTEGER,
  price: DataTypes.FLOAT,
});

module.exports = {
  core,

  async add(data) {
    return await this.core.bulkCreate(data, {
      updateOnDuplicate: Object.keys(data[0]),
    });
  },

  async get_pb_time(query) {
    return await this.core.findAll({ where: query });
  },
};
